package com.thoughtorigin.application {
import flash.utils.Dictionary;

public class XMLApplicationSettings implements ApplicationSettings {

    private var _feedDictionary: Dictionary;
    private var _baseFeedUrl: String;
    private var _baseSwfUrl: String;
    private var _baseContentUrl: String;
    private var _baseImageUrl: String;
    private var _crossDomainPolicies: Array;
    private var _additionalProperties: XMLList;

    public function XMLApplicationSettings(xmlSettings : XML) {
        _feedDictionary = new Dictionary(true);

        for each(var feed: XML in xmlSettings.feeds.feed) {
            var feedItem: FeedItem = new FeedItemForXMLSettings(feed.@id, feed.@url, feed.@method);
            _feedDictionary[feed.@id + ""] = feedItem;
        }

        _baseFeedUrl = xmlSettings.baseUrls.baseFeedUrl;
        _baseSwfUrl = xmlSettings.baseUrls.baseSwfUrl;
        _baseContentUrl = xmlSettings.baseUrls.baseContentUrl;
        _baseImageUrl = xmlSettings.baseUrls.baseImageUrl;

        _crossDomainPolicies = [];
        for each(var cdp: XML in xmlSettings.crossDomainPolicies.policy) {
            _crossDomainPolicies.push(cdp + "");
        }

        _additionalProperties = xmlSettings.additionalSettings;
    }

    public function get feeds():Dictionary {
        return _feedDictionary;
    }

    public function getFeedById(name:String):FeedItem {
        return _feedDictionary[name];
    }

    public function get baseFeedUrl():String {
        return _baseFeedUrl;
    }

    public function get baseSwfUrl():String {
        return _baseSwfUrl;
    }

    public function get baseContentUrl():String {
        return _baseContentUrl;
    }

    public function get baseImageUrl():String {
        return _baseImageUrl;
    }

    public function get crossDomainPolicies():Array {
        return _crossDomainPolicies;
    }

    public function get additionalProperties():Object {
        return _additionalProperties;
    }
}
}